package cn.twh.wall.util;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Service;

@Service
public class SpringUtil implements ApplicationContextAware {
    private static ApplicationContext ctx = null;

    public static <T> T getBean(String s, Class<T> requiredType) {
        return ctx.getBean(s, requiredType);
    }

    public static Object getBean(String s) {
        return ctx.getBean(s);
    }

    public static <T> T getBean(Class<T> requiredType) {
        return ctx.getBean(requiredType);
    }

    @Override
    public void setApplicationContext(ApplicationContext arg0) throws BeansException {
        ctx = arg0;
    }
}